# -*- coding:utf-8 -*-
class Solution:
    def convert(self, s, numRows):
        """
        :type s: str
        :type numRows: int
        :rtype: str
        """
        i = 0
        slist = list(s)
        length = len(slist)
        relist = []
        # 字符串长度为空返回
        if len(slist) == 0:
            return ""
        # 当分组数字为1返回源字符串
        if numRows == 1:
            return s
        for i in range(0, numRows):
            j = i
            # 第一行和最后一行
            if j % (numRows - 1) == 0:
                while j < length:
                    relist.append(slist[j])
                    j = j + 2 * (numRows - 1)
            # 中间的无数行
            else:
                while j < length:
                    mod = j % (numRows - 1)
                    relist.append(slist[j])
                    if j + 2 * (numRows - 1) - 2 * mod < length:
                        relist.append(slist[j + 2 * (numRows - 1) - 2 * mod])
                    j = j + 2 * (numRows - 1)
        return "".join(relist)


a = Solution()
# b = a.convert("ABCDEF", 5)
# b = a.convert("ABCDE", 4)
# b = a.convert("ABCD", 3)
# b = a.convert("AB", 1)
b = a.convert("A", 1)
print(b)
# a.convert("PAYPALISHIRING", 3)
